<template>
  <div class="zi-ding-yi-zujian">
    我是个很牛的input
    <input type="text" v-model="value" />
    <button @click="sendMsg">点我</button>
  </div>
</template>

<script>
import { inject } from 'vue';
export default {
  data() {
    return {
      value: '很牛的v-model',
    };
  },
  methods: {
    sendMsg() {
      this.$emit('mylord');
          console.log('transfer', this.$bus);
         this.$bus.$emit('transferData', '100');
    },
  },
  // inject: ['pageVal'],
  inject: {
    pageVal: {
      default: () => (''),
    }
  },
  mounted() {
    console.log('子组件的mounted加载');

    console.log('transfer', this.$bus);
    console.log('inject', this.pageVal);

    // 如果父级是放在mounted中创建bus那么需要nextTick
    // 但是最好父级在create中创建， 这样就可以直接用了
    // this.$nextTick(() => {
      this.$bus.$emit('transferData', '100');
    // })
    this.$emit('mylord');
    console.log('子组件的获取');
  },
};
</script>
